<HTML>
<HEAD>
<TITLE>Data Compression</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<link href="RaknetManual.css" rel="stylesheet" type="text/css">
<meta name="title" content="RakNet - Advanced multiplayer game networking API">
</HEAD><BODY BGCOLOR="#ffffff" LINK="#003399" vlink="#003399" alink="#003399" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0"">
<span style="background-color: rgb(255, 255, 255);"><img src="RakNet_Icon_Final-copy.jpg" alt="Oculus VR, Inc." width="150" height="150"></span><BR>
<BR>
<table width="100%" border="0">
  <tr>
    <td bgcolor="#2c5d92" class="RakNetWhiteHeader"><img src="spacer.gif" width="8" height="1">Data Compression Overview</td>
  </tr>
</table>
<TABLE BORDER="0" CELLPADDING="10" CELLSPACING="0" WIDTH="100%">
  <TR>
    <TD><span class="RakNetBlueHeader">Description </span><BR>
      <BR>
       RakNet can automatically compress all your outgoing data and decompress your incoming data.  To do this, it needs a 'sample' frequency table for your average game so it can pre-compute how to encode the data to get maximum savings.  Here is the general process of how to go about this:
      <OL>
        <LI>Run a sample 'average' game.  Get the frequency table for the server and for one of the clients (or average all the clients if you want).
        <LI>Generate the decompression layer for the server from the client's frequency table
        <LI>Generate the compression layer for the server from the server's frequency table
        <LI>Generate the decompression layer for the client from the server's frequency table
        <LI>Generate the compression layer for the client from the client's frequency table.
      </OL>
      After that everything is handled automatically.<BR>
      <BR>
      The functions are described below.  See Samples\Compression for a full example.  </TD>
  </TR>
</TABLE>
<table width="100%" border="0">
  <tr>
    <td bgcolor="#2c5d92" class="RakNetWhiteHeader"><img src="spacer.gif" width="8" height="1">Data Compression Functions</td>
  </tr>
</table>
<TABLE BORDER="0" CELLPADDING="10" CELLSPACING="0" WIDTH="100%">
<TR>
  <TD><span class="RakNetCode">SetCompileFrequencyTable( bool doCompile )</span><BR>
    <BR>
    
	Enables or disables frequency table tracking.  This is required to get a frequency table, which is used in GenerateCompressionLayer()
	This value persists between connect calls and defaults to false (no frequency tracking)
	You can call this at any time - however you SHOULD only call it when disconnected.  Otherwise you will only trackpart of the values sent over the network.
  
  <BR><BR>
  <span class="RakNetCode">GenerateCompressionLayer(unsigned long inputFrequencyTable[256], bool inputLayer)</span><BR>
    <BR>
    

	This is an optional function to generate the compression layer based on the input frequency table, which you get with GetOutgoingFrequencyTable.You should call this twice - once with inputLayer as true and once as false.
	The frequency table passed here with inputLayer=true should match the frequency table on the recipient with inputLayer=false.
	Likewise, the frequency table passed here with inputLayer=false should match the frequency table on the recipient with inputLayer=true.
	Calling this function when there is an existing layer will overwrite the old layer.
	<BR>
     <BR>
     <span class="RakNetCode">DeleteCompressionLayer(bool inputLayer) <BR>
     </span><BR>
    
	Delete the output or input layer as specified.  This is not necessary to call and is only valuable for freeing memory.
	You should only call this when disconnected<BR>
	
    <BR>
    <span class="RakNetCode">GetOutgoingFrequencyTable(unsigned long outputFrequencyTable[256]) </span><BR>
    <BR>
    
	Returns the frequency of outgoing bytes into output frequency table
	The purpose is to save to file as either a master frequency table from a sample game session for passing to GenerateCompressionLayer() .
	You should only call this when disconnected. Requires that you first enable data frequency tracking by calling SetCompileFrequencyTable(true)
	<BR>
	
    <BR>
    <span class="RakNetCode">float GetCompressionRatio </span><BR>
    <BR>
     This returns a number n > 0.0f where lower numbers are better.  n == 1.0f means your data is no smaller or greater than the original.  This shows how effective your compression rates are.<BR>
	
    <BR>
    <span class="RakNetCode">float GetDecompressionRatio </span><BR>
    <BR>
     This returns a number n > 0.0f where higher numbers are better.  n == 1.0f means the incoming data was decompressed to be just as large as it was when it came in.  This shows how effective your compression rates are.<BR>
	
    <BR>
    <table width="100%" border="0">
      <tr>
        <td bgcolor="#2c5d92" class="RakNetWhiteHeader"><img src="spacer.gif" width="8" height="1">See Also</td>
      </tr>
    </table>
    <TABLE BORDER="0" CELLPADDING="10" CELLSPACING="0" WIDTH="100%">
      <TR>
        <TD> <A HREF="index.html">Index</A><BR>           </TD>
      </TR>
    </TABLE></TD>
</TR></TABLE>
</BODY>
</HTML>
